package org.hawk.gwt.ppc.parser.impl;

import java.util.List;

import org.hawk.gwt.ppc.parser.AnnotationDescriptor;
import org.hawk.gwt.ppc.parser.BlockDescriptor;
import org.hawk.gwt.ppc.parser.Descriptor;
import org.hawk.gwt.ppc.parser.DescriptorVisitor;
import org.hawk.gwt.ppc.parser.ExpressionDescriptor;
import org.hawk.gwt.ppc.parser.MethodDescriptor;
import org.hawk.gwt.ppc.parser.Token;
import org.hawk.gwt.ppc.parser.VariableDescriptor;
import org.hawk.gwt.ppc.utils.PreprocessorException;

/**
 * {@link MethodDescriptor} internal implementation.
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
final class MethodDescriptorImpl extends AbstractParameterizedMemberDescriptor
		implements MethodDescriptor {
	
	private String name;
	private String returnType;
	private String typeParameters;
	private BlockDescriptor body;
	private ExpressionDescriptor defaultExpression;

	MethodDescriptorImpl(Token first,
			Token last, String name,
			String returnType,
			String typeParameters,
			List<String> modifiers,
			BlockDescriptor body,
			ExpressionDescriptor defaultExpression,
			List<AnnotationDescriptor> annotations,
			List<VariableDescriptor> parameters, 
			List<String> exceptions,
			List<Descriptor> descriptors, 
			boolean varArgs) {
		super(first, last, modifiers, annotations, parameters, exceptions, descriptors, varArgs);
		
		this.name = name;
		this.returnType = returnType;
		this.typeParameters = typeParameters;
		this.body = body;
		this.defaultExpression = defaultExpression;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.MethodDescriptor#getName()
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.MethodDescriptor#getBody()
	 */
	public BlockDescriptor getBody() {
		return body;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.MethodDescriptor#getReturnType()
	 */
	public String getReturnType() {
		return returnType;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.MethodDescriptor#getTypeParameters()
	 */
	public String getTypeParameters() {
		return typeParameters;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.MethodDescriptor#getDefault()
	 */
	public ExpressionDescriptor getDefault() {
		return defaultExpression;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.Descriptor#visit(org.hawk.gwt.ppc.parser.DescriptorVisitor)
	 */
	public void visit(DescriptorVisitor visitor) throws PreprocessorException {
		visitor.visit(this);
		if (body != null) {
			body.visit(visitor);
		}
		if (defaultExpression != null) {
			defaultExpression.visit(visitor);
		}
	}
}
